<?php
/**
 * Pertyler
 * Connector Row Redirected To Object Browser Page
 *
 * @author	Emre Hasegeli <hasegeli@gmail.com>
 * @license	GNU General Public License v3
 */

namespace Pertyler;

require '../databaseModel/Table.php';

require '../databaseModel/Role.php';

require '../control/main.php';

if(!($moderator = Role_Moderator::Select()))
	if(require '../control/Index.php')
		return;

if((empty(\Pert\Page::Get()->ParentTable)) OR (empty(\Pert\Page::Get()->Row)))
	return false;

if(!Table::Select(\Pert\Page::Get()->ParentTable)->ConnectorTable())
	return false;

$parentTable = Table::Select(\Pert\Page::Get()->ParentTable);

$row = $parentTable->SelectRow(\Pert\Page::Get()->Row);

$columnValueArray = $row->SelectColumnValueArray();

$parentTable = $columnValueArray[1]->Column()->RelatedTable();

$row = $columnValueArray[1]->Value();

if(!$row)
	throw new Exception('Row cannot found');

unset($columnValueArray);

\Pert\Page::Get()->ParentTable = $parentTable->Id();

\Pert\Page::Get()->Row = $row->Id();

require 'ObjectBrowser.php';
